// ============================== 导入依赖 ============================== //

import CORE from '@login/CORE'
import TRANS from '@demo/CORE/UTIL/init/TRANS'

import Client from '@api/user/api/SysRegionApi'

import ComClass from '@api/ComQuery'
import TreeClass from '@api/user/model/SysRegionDto'

const CLIENT = CORE.grpcCLIENT(Client)
const PARAM = { page: 1, pageSize: 10000 }
const COM = [ComClass, 'comQuery']

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 结构树 —————————————————————————————— //

  async getRegion(name = CORE.MAP.REGION) {
    if (sessionStorage.REGION) return JSON.parse(sessionStorage.REGION)

    const DTO = CORE.grpcDTO(TreeClass, PARAM, COM)
    const resp = await CORE.grpc(TRANS.transTip(name), CLIENT, 'sysRegionQuery', DTO)
    const REGION = resp.content || []

    sessionStorage.REGION = JSON.stringify(REGION)

    return REGION
  },
}
